package cn.mayday.algorithms.year2021.month1.深度优先遍历;

/**
 * 剑指 Offer 55 - I. 二叉树的深度
 * [简单]
 *
 * @author Mayday05
 * @date 2021/5/12 14:50
 */
public class Offer055MaxDepth {


    public static void main(String[] args) {

    }


    /**
     * 直接DFS 递归遍历即可
     *
     * @param root
     * @return
     */

    public int maxDepth(TreeNode root) {
        if (root == null) {
            return 0;
        }
        return 1+Math.max(maxDepth(root.left), maxDepth(root.right));
    }


    //Definition for a binary tree node.
    public class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }
}
